package com.example.yifei.ui.page.main.workOrder

import android.annotation.SuppressLint
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.lazy.LazyListState
import androidx.compose.material.ExperimentalMaterialApi
import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.dp
import androidx.hilt.navigation.compose.hiltViewModel
import androidx.navigation.NavHostController
import androidx.paging.compose.collectAsLazyPagingItems
import androidx.paging.compose.itemsIndexed
import coil.annotation.ExperimentalCoilApi
import com.example.yifei.ui.page.main.workOrder.item.WorkOrderPageItem
import com.example.yifei.ui.page.widgets.RefreshList
import com.example.yifei.ui.page.widgets.TitleBar

/**
 * @Author: zhudaihao
 * @Date: 2022/5/12
 * @Describe: 生产工单
 */

@ExperimentalCoilApi
@SuppressLint("RememberReturnType")
@ExperimentalMaterialApi
@Composable
fun ConfirmedPage(
    navCtrl: NavHostController,
    viewModel: WorkOrderViewModel = hiltViewModel()
) {
    val viewStates = remember { viewModel.viewStates }
    val squareData = viewStates.pagingData.collectAsLazyPagingItems()
    val listState = if (squareData.itemCount > 0) viewStates.listState else LazyListState()

    Column {

        TitleBar(title = "生产工单", onClickSearch = {
            //搜索

        }, onClickScreen = {
            //筛选

        })

        Box(
            modifier = Modifier
                .background(Color(0xffF4F6FB))
                .padding(bottom = 56.dp, start = 8.dp, end = 8.dp)
        ) {
            RefreshList(squareData, listState = listState) {
                itemsIndexed(squareData) { _, it ->
                    WorkOrderPageItem(it, navCtrl = navCtrl)
                }
            }
        }

    }

}


